﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Draco.OWF.RT
{
    public class JobContext : IJobContext
    {
        protected String m_SessionId = Guid.NewGuid().ToString();
        protected IJobContext m_ParentContext = null;
        protected IProcess m_ProcessDefinition;
        protected IJob m_ProcessInstance;

        /// <summary>
        /// SessionId
        /// </summary>
        public virtual string SessionId
        {
            get
            {
                return m_SessionId;
            }
            set
            {
                if (m_SessionId != null) m_SessionId=value;
            }
        }

        public virtual IJobContext ParentContext
        {
            get { return m_ParentContext; }
        }

        public virtual IProcess ProcessDefinition
        {
            get { return m_ProcessDefinition; }
        }

        public virtual IJob ProcessInstance
        {
            get { return m_ProcessInstance; }
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="processInstance"></param>
        public JobContext(IJob processInstance)
            : this(processInstance,null)
        {
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="processInstance"></param>
        /// <param name="parent"></param>
        public JobContext(IJob processInstance,IJobContext parent)
        {
            if (processInstance == null)
                throw new ArgumentNullException();
            m_ProcessInstance = processInstance;
            m_ProcessDefinition = processInstance.WorkflowDefine;
            m_ParentContext = parent;
        }
    }
}
